package com.simplenix.rush;

import com.simplenix.rush.db.Note;
import com.simplenix.rush.db.comparators.NoteNameComparator;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import net.sourceforge.floggy.persistence.FloggyException;
import net.sourceforge.floggy.persistence.ObjectSet;
import net.sourceforge.floggy.persistence.PersistableManager;

/**
 * @author fronald
 */
public class RushNotes extends MIDlet implements CommandListener, ItemCommandListener {

    private boolean midletPaused = false;
    private boolean backToList = false;

    //<editor-fold defaultstate="collapsed" desc=" Generated Fields ">//GEN-BEGIN:|fields|0|
    private Command exitCommand;
    private Command okCommand;
    private Command backCommand;
    private Command showListCommand;
    private Command showAboutCommand;
    private Command backCommand1;
    private Command addCommand;
    private Command backCommand2;
    private Command backCommand3;
    private Command backCommand4;
    private Command okCommand1;
    private Command addUpdate;
    private Command okCommand2;
    private Command deleteCommand;
    private Command editarCommand;
    private Command voltarAboutCommand;
    private Form welcome;
    private StringItem opcaoSobre;
    private StringItem opcaoLista;
    private List listNotes;
    private TextBox updateNote;
    private Form noteName;
    private TextField txtNoteName;
    private TextBox aboutScreen;
    //</editor-fold>//GEN-END:|fields|0|

    /**
     * The RushNotes constructor.
     */
    public RushNotes() {
    }

    //<editor-fold defaultstate="collapsed" desc=" Generated Methods ">//GEN-BEGIN:|methods|0|
    //</editor-fold>//GEN-END:|methods|0|

    //<editor-fold defaultstate="collapsed" desc=" Generated Method: initialize ">//GEN-BEGIN:|0-initialize|0|0-preInitialize
    /**
     * Initilizes the application.
     * It is called only once when the MIDlet is started. The method is called before the <code>startMIDlet</code> method.
     */
    private void initialize() {//GEN-END:|0-initialize|0|0-preInitialize
        // write pre-initialize user code here
        okCommand = new Command("Ok", Command.OK, 0);//GEN-BEGIN:|0-initialize|1|0-postInitialize
        okCommand1 = new Command("Ok", Command.OK, 0);//GEN-END:|0-initialize|1|0-postInitialize
    // write post-initialize user code here
    }//GEN-BEGIN:|0-initialize|2|
    //</editor-fold>//GEN-END:|0-initialize|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Method: startMIDlet ">//GEN-BEGIN:|3-startMIDlet|0|3-preAction
    /**
     * Performs an action assigned to the Mobile Device - MIDlet Started point.
     */
    public void startMIDlet() {//GEN-END:|3-startMIDlet|0|3-preAction
        // write pre-action user code here
        switchDisplayable(null, getWelcome());//GEN-LINE:|3-startMIDlet|1|3-postAction
    // write post-action user code here
    }//GEN-BEGIN:|3-startMIDlet|2|
    //</editor-fold>//GEN-END:|3-startMIDlet|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Method: resumeMIDlet ">//GEN-BEGIN:|4-resumeMIDlet|0|4-preAction
    /**
     * Performs an action assigned to the Mobile Device - MIDlet Resumed point.
     */
    public void resumeMIDlet() {//GEN-END:|4-resumeMIDlet|0|4-preAction
        // write pre-action user code here
//GEN-LINE:|4-resumeMIDlet|1|4-postAction
        // write post-action user code here
    }//GEN-BEGIN:|4-resumeMIDlet|2|
    //</editor-fold>//GEN-END:|4-resumeMIDlet|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Method: switchDisplayable ">//GEN-BEGIN:|5-switchDisplayable|0|5-preSwitch
    /**
     * Switches a current displayable in a display. The <code>display</code> instance is taken from <code>getDisplay</code> method. This method is used by all actions in the design for switching displayable.
     * @param alert the Alert which is temporarily set to the display; if <code>null</code>, then <code>nextDisplayable</code> is set immediately
     * @param nextDisplayable the Displayable to be set
     */
    public void switchDisplayable(Alert alert, Displayable nextDisplayable) {//GEN-END:|5-switchDisplayable|0|5-preSwitch
        // write pre-switch user code here
        Display display = getDisplay();//GEN-BEGIN:|5-switchDisplayable|1|5-postSwitch
        if (alert == null) {
            display.setCurrent(nextDisplayable);
        } else {
            display.setCurrent(alert, nextDisplayable);
        }//GEN-END:|5-switchDisplayable|1|5-postSwitch
    // write post-switch user code here
    }//GEN-BEGIN:|5-switchDisplayable|2|
    //</editor-fold>//GEN-END:|5-switchDisplayable|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Method: commandAction for Displayables ">//GEN-BEGIN:|7-commandAction|0|7-preCommandAction
    /**
     * Called by a system to indicated that a command has been invoked on a particular displayable.
     * @param command the Command that was invoked
     * @param displayable the Displayable where the command was invoked
     */
    public void commandAction(Command command, Displayable displayable) {//GEN-END:|7-commandAction|0|7-preCommandAction
        // write pre-action user code here
        if (displayable == aboutScreen) {//GEN-BEGIN:|7-commandAction|1|99-preAction
            if (command == voltarAboutCommand) {//GEN-END:|7-commandAction|1|99-preAction
                // write pre-action user code here
                switchDisplayable(null, getWelcome());//GEN-LINE:|7-commandAction|2|99-postAction
            // write post-action user code here
            }//GEN-BEGIN:|7-commandAction|3|26-preAction
        } else if (displayable == listNotes) {
            if (command == List.SELECT_COMMAND) {//GEN-END:|7-commandAction|3|26-preAction
                // write pre-action user code here
                listNotesAction();//GEN-LINE:|7-commandAction|4|26-postAction
            // write post-action user code here
            } else if (command == addCommand) {//GEN-LINE:|7-commandAction|5|51-preAction
                // write pre-action user code here
                this.getNoteName();
                this.getUpdateNote();
                this.txtNoteName.setString("");
                this.updateNote.setString("");
                switchDisplayable(null, getNoteName());//GEN-LINE:|7-commandAction|6|51-postAction
            // write post-action user code here
            } else if (command == backCommand) {//GEN-LINE:|7-commandAction|7|30-preAction
                // write pre-action user code here
                switchDisplayable(null, getWelcome());//GEN-LINE:|7-commandAction|8|30-postAction
            // write post-action user code here
            } else if (command == deleteCommand) {//GEN-LINE:|7-commandAction|9|94-preAction
                // write pre-action user code here
                if (this.listNotes.getSelectedIndex() >= 0) {
                    String nname = listNotes.getString(this.listNotes.getSelectedIndex());
                    Note.deleteNoteByName(nname);
                }
                this.refreshListNotes();
                switchDisplayable(null, getListNotes());
//GEN-LINE:|7-commandAction|10|94-postAction
            // write post-action user code here
            } else if (command == editarCommand) {//GEN-LINE:|7-commandAction|11|92-preAction
                // write pre-action user code here
                this.backToList = true;
                if (this.listNotes.getSelectedIndex() >= 0) {
                    this.getTxtNoteName();
                    this.getUpdateNote();
                    String nname = listNotes.getString(this.listNotes.getSelectedIndex());
                    this.txtNoteName.setString(nname);
                    Note selectedNote = Note.getNoteByName(nname);
                    this.updateNote.setString(selectedNote.getNote());
                }
                if (this.listNotes.size() > 0) {
                    switchDisplayable(null, getUpdateNote());//GEN-LINE:|7-commandAction|12|92-postAction
                }
            // write post-action user code here
            }//GEN-BEGIN:|7-commandAction|13|76-preAction
        } else if (displayable == noteName) {
            if (command == addUpdate) {//GEN-END:|7-commandAction|13|76-preAction
                // write pre-action user code here
                // um ovinho de pascoa romantico :-D
                if (this.txtNoteName.getString().equalsIgnoreCase("Franklin") || this.txtNoteName.getString().equalsIgnoreCase("Frank")) {
                    this.updateNote = this.getUpdateNote();
                    this.updateNote.setString("Ama a Carol :-D");
                }
                if (this.txtNoteName.getString().equalsIgnoreCase("Carol") || this.txtNoteName.getString().equalsIgnoreCase("Carolina")) {
                    this.updateNote = this.getUpdateNote();
                    this.updateNote.setString("Ama o Franklin :-D");
                }
                noteNameValido();//GEN-LINE:|7-commandAction|14|76-postAction
            // write post-action user code here
            } else if (command == backCommand4) {//GEN-LINE:|7-commandAction|15|70-preAction
                // write pre-action user code here
                switchDisplayable(null, getListNotes());//GEN-LINE:|7-commandAction|16|70-postAction
            // write post-action user code here
            }//GEN-BEGIN:|7-commandAction|17|64-preAction
        } else if (displayable == updateNote) {
            if (command == backCommand3) {//GEN-END:|7-commandAction|17|64-preAction
                // write pre-action user code here
                if (!this.backToList) {
                    switchDisplayable(null, getNoteName());//GEN-LINE:|7-commandAction|18|64-postAction
                } else {
                    this.refreshListNotes();
                    switchDisplayable(null, getListNotes());
                }
            // write post-action user code here
            } else if (command == okCommand2) {//GEN-LINE:|7-commandAction|19|87-preAction
                // write pre-action user code here
                incluiu();//GEN-LINE:|7-commandAction|20|87-postAction
            // write post-action user code here
            }//GEN-BEGIN:|7-commandAction|21|19-preAction
        } else if (displayable == welcome) {
            if (command == exitCommand) {//GEN-END:|7-commandAction|21|19-preAction
                // write pre-action user code here
                exitMIDlet();//GEN-LINE:|7-commandAction|22|19-postAction
            // write post-action user code here
            }//GEN-BEGIN:|7-commandAction|23|7-postCommandAction
        }//GEN-END:|7-commandAction|23|7-postCommandAction
    // write post-action user code here
    }//GEN-BEGIN:|7-commandAction|24|
    //</editor-fold>//GEN-END:|7-commandAction|24|


    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: exitCommand ">//GEN-BEGIN:|18-getter|0|18-preInit
    /**
     * Returns an initiliazed instance of exitCommand component.
     * @return the initialized component instance
     */
    public Command getExitCommand() {
        if (exitCommand == null) {//GEN-END:|18-getter|0|18-preInit
            // write pre-init user code here
            exitCommand = new Command("Sair", Command.EXIT, 0);//GEN-LINE:|18-getter|1|18-postInit
        // write post-init user code here
        }//GEN-BEGIN:|18-getter|2|
        return exitCommand;
    }
    //</editor-fold>//GEN-END:|18-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: welcome ">//GEN-BEGIN:|14-getter|0|14-preInit
    /**
     * Returns an initiliazed instance of welcome component.
     * @return the initialized component instance
     */
    public Form getWelcome() {
        if (welcome == null) {//GEN-END:|14-getter|0|14-preInit
            // write pre-init user code here
            welcome = new Form("RushNotes", new Item[] { getOpcaoLista(), getOpcaoSobre() });//GEN-BEGIN:|14-getter|1|14-postInit
            welcome.addCommand(getExitCommand());
            welcome.setCommandListener(this);//GEN-END:|14-getter|1|14-postInit
        // write post-init user code here
        }//GEN-BEGIN:|14-getter|2|
        return welcome;
    }
    //</editor-fold>//GEN-END:|14-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: backCommand ">//GEN-BEGIN:|29-getter|0|29-preInit
    /**
     * Returns an initiliazed instance of backCommand component.
     * @return the initialized component instance
     */
    public Command getBackCommand() {
        if (backCommand == null) {//GEN-END:|29-getter|0|29-preInit
            // write pre-init user code here
            backCommand = new Command("Voltar", Command.BACK, 0);//GEN-LINE:|29-getter|1|29-postInit
        // write post-init user code here
        }//GEN-BEGIN:|29-getter|2|
        return backCommand;
    }
    //</editor-fold>//GEN-END:|29-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: listNotes ">//GEN-BEGIN:|24-getter|0|24-preInit
    /**
     * Returns an initiliazed instance of listNotes component.
     * @return the initialized component instance
     */
    public List getListNotes() {
        if (listNotes == null) {//GEN-END:|24-getter|0|24-preInit
            // write pre-init user code here
            listNotes = new List("Minhas Notas", Choice.IMPLICIT);//GEN-BEGIN:|24-getter|1|24-postInit
            listNotes.addCommand(getBackCommand());
            listNotes.addCommand(getAddCommand());
            listNotes.addCommand(getEditarCommand());
            listNotes.addCommand(getDeleteCommand());
            listNotes.setCommandListener(this);//GEN-END:|24-getter|1|24-postInit
            this.refreshListNotes();
        // write post-init user code here
        }//GEN-BEGIN:|24-getter|2|
        return listNotes;
    }
    //</editor-fold>//GEN-END:|24-getter|2|

    private void refreshListNotes() {
        try {
            this.backToList = false;
            listNotes.deleteAll();
            ObjectSet notes = PersistableManager.getInstance().find(Note.class, null, new NoteNameComparator());
            for (int i = 0; i < notes.size(); i++) {
                Note note = (Note) notes.get(i);
                listNotes.append(note.getName(), null);
            }
        } catch (FloggyException ex) {
            ex.printStackTrace();
        }
    }

    //<editor-fold defaultstate="collapsed" desc=" Generated Method: listNotesAction ">//GEN-BEGIN:|24-action|0|24-preAction
    /**
     * Performs an action assigned to the selected list element in the listNotes component.
     */
    public void listNotesAction() {//GEN-END:|24-action|0|24-preAction
        // enter pre-action user code here
        String __selectedString = getListNotes().getString(getListNotes().getSelectedIndex());//GEN-LINE:|24-action|1|24-postAction
    // enter post-action user code here
    }//GEN-BEGIN:|24-action|2|
    //</editor-fold>//GEN-END:|24-action|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: opcaoLista ">//GEN-BEGIN:|33-getter|0|33-preInit
    /**
     * Returns an initiliazed instance of opcaoLista component.
     * @return the initialized component instance
     */
    public StringItem getOpcaoLista() {
        if (opcaoLista == null) {//GEN-END:|33-getter|0|33-preInit
            // write pre-init user code here
            opcaoLista = new StringItem("Minhas Notas...", "");//GEN-BEGIN:|33-getter|1|33-postInit
            opcaoLista.addCommand(getShowListCommand());
            opcaoLista.setItemCommandListener(this);//GEN-END:|33-getter|1|33-postInit
        // write post-init user code here
        }//GEN-BEGIN:|33-getter|2|
        return opcaoLista;
    }
    //</editor-fold>//GEN-END:|33-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: opcaoSobre ">//GEN-BEGIN:|34-getter|0|34-preInit
    /**
     * Returns an initiliazed instance of opcaoSobre component.
     * @return the initialized component instance
     */
    public StringItem getOpcaoSobre() {
        if (opcaoSobre == null) {//GEN-END:|34-getter|0|34-preInit
            // write pre-init user code here
            opcaoSobre = new StringItem("Sobre...", "");//GEN-BEGIN:|34-getter|1|34-postInit
            opcaoSobre.addCommand(getShowAboutCommand());
            opcaoSobre.setItemCommandListener(this);//GEN-END:|34-getter|1|34-postInit
        // write post-init user code here
        }//GEN-BEGIN:|34-getter|2|
        return opcaoSobre;
    }
    //</editor-fold>//GEN-END:|34-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Method: commandAction for Items ">//GEN-BEGIN:|17-itemCommandAction|0|17-preItemCommandAction
    /**
     * Called by a system to indicated that a command has been invoked on a particular item.
     * @param command the Command that was invoked
     * @param displayable the Item where the command was invoked
     */
    public void commandAction(Command command, Item item) {//GEN-END:|17-itemCommandAction|0|17-preItemCommandAction
        // write pre-action user code here
        if (item == opcaoLista) {//GEN-BEGIN:|17-itemCommandAction|1|36-preAction
            if (command == showListCommand) {//GEN-END:|17-itemCommandAction|1|36-preAction
                // write pre-action user code here
                switchDisplayable(null, getListNotes());//GEN-LINE:|17-itemCommandAction|2|36-postAction
            // write post-action user code here
            }//GEN-BEGIN:|17-itemCommandAction|3|38-preAction
        } else if (item == opcaoSobre) {
            if (command == showAboutCommand) {//GEN-END:|17-itemCommandAction|3|38-preAction
                // write pre-action user code here
                switchDisplayable(null, getAboutScreen());//GEN-LINE:|17-itemCommandAction|4|38-postAction
            // write post-action user code here
            }//GEN-BEGIN:|17-itemCommandAction|5|17-postItemCommandAction
        }//GEN-END:|17-itemCommandAction|5|17-postItemCommandAction
    // write post-action user code here
    }//GEN-BEGIN:|17-itemCommandAction|6|
    //</editor-fold>//GEN-END:|17-itemCommandAction|6|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: showListCommand ">//GEN-BEGIN:|35-getter|0|35-preInit
    /**
     * Returns an initiliazed instance of showListCommand component.
     * @return the initialized component instance
     */
    public Command getShowListCommand() {
        if (showListCommand == null) {//GEN-END:|35-getter|0|35-preInit
            // write pre-init user code here
            showListCommand = new Command("Ir", Command.OK, 0);//GEN-LINE:|35-getter|1|35-postInit
        // write post-init user code here
        }//GEN-BEGIN:|35-getter|2|
        return showListCommand;
    }
    //</editor-fold>//GEN-END:|35-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: showAboutCommand ">//GEN-BEGIN:|37-getter|0|37-preInit
    /**
     * Returns an initiliazed instance of showAboutCommand component.
     * @return the initialized component instance
     */
    public Command getShowAboutCommand() {
        if (showAboutCommand == null) {//GEN-END:|37-getter|0|37-preInit
            // write pre-init user code here
            showAboutCommand = new Command("Ir", Command.OK, 0);//GEN-LINE:|37-getter|1|37-postInit
        // write post-init user code here
        }//GEN-BEGIN:|37-getter|2|
        return showAboutCommand;
    }
    //</editor-fold>//GEN-END:|37-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: backCommand1 ">//GEN-BEGIN:|47-getter|0|47-preInit
    /**
     * Returns an initiliazed instance of backCommand1 component.
     * @return the initialized component instance
     */
    public Command getBackCommand1() {
        if (backCommand1 == null) {//GEN-END:|47-getter|0|47-preInit
            // write pre-init user code here
            backCommand1 = new Command("Back", Command.BACK, 0);//GEN-LINE:|47-getter|1|47-postInit
        // write post-init user code here
        }//GEN-BEGIN:|47-getter|2|
        return backCommand1;
    }
    //</editor-fold>//GEN-END:|47-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: addCommand ">//GEN-BEGIN:|50-getter|0|50-preInit
    /**
     * Returns an initiliazed instance of addCommand component.
     * @return the initialized component instance
     */
    public Command getAddCommand() {
        if (addCommand == null) {//GEN-END:|50-getter|0|50-preInit
            // write pre-init user code here
            addCommand = new Command("Nova...", Command.SCREEN, 0);//GEN-LINE:|50-getter|1|50-postInit
        // write post-init user code here
        }//GEN-BEGIN:|50-getter|2|
        return addCommand;
    }
    //</editor-fold>//GEN-END:|50-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: backCommand2 ">//GEN-BEGIN:|55-getter|0|55-preInit
    /**
     * Returns an initiliazed instance of backCommand2 component.
     * @return the initialized component instance
     */
    public Command getBackCommand2() {
        if (backCommand2 == null) {//GEN-END:|55-getter|0|55-preInit
            // write pre-init user code here
            backCommand2 = new Command("Voltar", Command.BACK, 0);//GEN-LINE:|55-getter|1|55-postInit
        // write post-init user code here
        }//GEN-BEGIN:|55-getter|2|
        return backCommand2;
    }
    //</editor-fold>//GEN-END:|55-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: updateNote ">//GEN-BEGIN:|61-getter|0|61-preInit
    /**
     * Returns an initiliazed instance of updateNote component.
     * @return the initialized component instance
     */
    public TextBox getUpdateNote() {
        if (updateNote == null) {//GEN-END:|61-getter|0|61-preInit
            // write pre-init user code here
            updateNote = new TextBox("Editar nota", null, 100, TextField.ANY);//GEN-BEGIN:|61-getter|1|61-postInit
            updateNote.addCommand(getBackCommand3());
            updateNote.addCommand(getOkCommand2());
            updateNote.setCommandListener(this);//GEN-END:|61-getter|1|61-postInit
        // write post-init user code here
        }//GEN-BEGIN:|61-getter|2|
        return updateNote;
    }
    //</editor-fold>//GEN-END:|61-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: backCommand3 ">//GEN-BEGIN:|63-getter|0|63-preInit
    /**
     * Returns an initiliazed instance of backCommand3 component.
     * @return the initialized component instance
     */
    public Command getBackCommand3() {
        if (backCommand3 == null) {//GEN-END:|63-getter|0|63-preInit
            // write pre-init user code here
            backCommand3 = new Command("Voltar", Command.BACK, 0);//GEN-LINE:|63-getter|1|63-postInit
        // write post-init user code here
        }//GEN-BEGIN:|63-getter|2|
        return backCommand3;
    }
    //</editor-fold>//GEN-END:|63-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: backCommand4 ">//GEN-BEGIN:|69-getter|0|69-preInit
    /**
     * Returns an initiliazed instance of backCommand4 component.
     * @return the initialized component instance
     */
    public Command getBackCommand4() {
        if (backCommand4 == null) {//GEN-END:|69-getter|0|69-preInit
            // write pre-init user code here
            backCommand4 = new Command("Voltar", Command.BACK, 0);//GEN-LINE:|69-getter|1|69-postInit
        // write post-init user code here
        }//GEN-BEGIN:|69-getter|2|
        return backCommand4;
    }
    //</editor-fold>//GEN-END:|69-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: noteName ">//GEN-BEGIN:|66-getter|0|66-preInit
    /**
     * Returns an initiliazed instance of noteName component.
     * @return the initialized component instance
     */
    public Form getNoteName() {
        if (noteName == null) {//GEN-END:|66-getter|0|66-preInit
            // write pre-init user code here
            noteName = new Form("Nova Nota", new Item[] { getTxtNoteName() });//GEN-BEGIN:|66-getter|1|66-postInit
            noteName.addCommand(getBackCommand4());
            noteName.addCommand(getAddUpdate());
            noteName.setCommandListener(this);//GEN-END:|66-getter|1|66-postInit
        // write post-init user code here
        }//GEN-BEGIN:|66-getter|2|
        return noteName;
    }
    //</editor-fold>//GEN-END:|66-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: addUpdate ">//GEN-BEGIN:|75-getter|0|75-preInit
    /**
     * Returns an initiliazed instance of addUpdate component.
     * @return the initialized component instance
     */
    public Command getAddUpdate() {
        if (addUpdate == null) {//GEN-END:|75-getter|0|75-preInit
            // write pre-init user code here
            addUpdate = new Command("Cont.", Command.OK, 0);//GEN-LINE:|75-getter|1|75-postInit
        // write post-init user code here
        }//GEN-BEGIN:|75-getter|2|
        return addUpdate;
    }
    //</editor-fold>//GEN-END:|75-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: txtNoteName ">//GEN-BEGIN:|71-getter|0|71-preInit
    /**
     * Returns an initiliazed instance of txtNoteName component.
     * @return the initialized component instance
     */
    public TextField getTxtNoteName() {
        if (txtNoteName == null) {//GEN-END:|71-getter|0|71-preInit
            // write pre-init user code here
            txtNoteName = new TextField("Nome", null, 32, TextField.ANY);//GEN-LINE:|71-getter|1|71-postInit
        // write post-init user code here
        }//GEN-BEGIN:|71-getter|2|
        return txtNoteName;
    }
    //</editor-fold>//GEN-END:|71-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Method: noteNameValido ">//GEN-BEGIN:|77-if|0|77-preIf
    /**
     * Performs an action assigned to the noteNameValido if-point.
     */
    public void noteNameValido() {//GEN-END:|77-if|0|77-preIf
        // enter pre-if user code here
        if (!com.simplenix.rush.misc.Utils.nvl(this.txtNoteName.getString()).equals("") && !com.simplenix.rush.db.Note.exists(com.simplenix.rush.misc.Utils.nvl(this.txtNoteName.getString()))) {//GEN-LINE:|77-if|1|78-preAction
            // write pre-action user code here
            this.refreshListNotes();
            switchDisplayable(null, getUpdateNote());//GEN-LINE:|77-if|2|78-postAction
        // write post-action user code here
        } else {//GEN-LINE:|77-if|3|79-preAction
            // write pre-action user code here
            switchDisplayable(null, getNoteName());//GEN-LINE:|77-if|4|79-postAction
        // write post-action user code here
        }//GEN-LINE:|77-if|5|77-postIf
    // enter post-if user code here
    }//GEN-BEGIN:|77-if|6|
    //</editor-fold>//GEN-END:|77-if|6|

    //<editor-fold defaultstate="collapsed" desc=" Generated Method: incluiu ">//GEN-BEGIN:|83-if|0|83-preIf
    /**
     * Performs an action assigned to the incluiu if-point.
     */
    public void incluiu() {//GEN-END:|83-if|0|83-preIf
        // enter pre-if user code here
        Note newNote = new Note();
        newNote.setName(this.txtNoteName.getString());
        newNote.setNote(this.updateNote.getString());
        if (com.simplenix.rush.db.Note.incluiu(newNote)) {//GEN-LINE:|83-if|1|84-preAction
            // write pre-action user code here
            switchDisplayable(null, getListNotes());//GEN-LINE:|83-if|2|84-postAction
            // write post-action user code here
            this.refreshListNotes();
        } else {//GEN-LINE:|83-if|3|85-preAction
            // write pre-action user code here
            switchDisplayable(null, getUpdateNote());//GEN-LINE:|83-if|4|85-postAction
        // write post-action user code here
        }//GEN-LINE:|83-if|5|83-postIf
    // enter post-if user code here
    }//GEN-BEGIN:|83-if|6|
    //</editor-fold>//GEN-END:|83-if|6|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: okCommand2 ">//GEN-BEGIN:|86-getter|0|86-preInit
    /**
     * Returns an initiliazed instance of okCommand2 component.
     * @return the initialized component instance
     */
    public Command getOkCommand2() {
        if (okCommand2 == null) {//GEN-END:|86-getter|0|86-preInit
            // write pre-init user code here
            okCommand2 = new Command("Salvar", Command.OK, 0);//GEN-LINE:|86-getter|1|86-postInit
        // write post-init user code here
        }//GEN-BEGIN:|86-getter|2|
        return okCommand2;
    }
    //</editor-fold>//GEN-END:|86-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: editarCommand ">//GEN-BEGIN:|91-getter|0|91-preInit
    /**
     * Returns an initiliazed instance of editarCommand component.
     * @return the initialized component instance
     */
    public Command getEditarCommand() {
        if (editarCommand == null) {//GEN-END:|91-getter|0|91-preInit
            // write pre-init user code here
            editarCommand = new Command("Ver/Editar", Command.OK, 0);//GEN-LINE:|91-getter|1|91-postInit
        // write post-init user code here
        }//GEN-BEGIN:|91-getter|2|
        return editarCommand;
    }
    //</editor-fold>//GEN-END:|91-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: deleteCommand ">//GEN-BEGIN:|93-getter|0|93-preInit
    /**
     * Returns an initiliazed instance of deleteCommand component.
     * @return the initialized component instance
     */
    public Command getDeleteCommand() {
        if (deleteCommand == null) {//GEN-END:|93-getter|0|93-preInit
            // write pre-init user code here
            deleteCommand = new Command("Deletar", Command.OK, 0);//GEN-LINE:|93-getter|1|93-postInit
        // write post-init user code here
        }//GEN-BEGIN:|93-getter|2|
        return deleteCommand;
    }
    //</editor-fold>//GEN-END:|93-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: aboutScreen ">//GEN-BEGIN:|96-getter|0|96-preInit
    /**
     * Returns an initiliazed instance of aboutScreen component.
     * @return the initialized component instance
     */
    public TextBox getAboutScreen() {
        if (aboutScreen == null) {//GEN-END:|96-getter|0|96-preInit
            // write pre-init user code here
            aboutScreen = new TextBox("Sobre o RushNotes", "RushNotes v1.0\npor Franklin Ronald\n\nhttp://rushnotes.googlecode.com\nhttp://ticorporativa.blogspot.com\n\n", 130, TextField.ANY | TextField.UNEDITABLE);//GEN-BEGIN:|96-getter|1|96-postInit
            aboutScreen.addCommand(getVoltarAboutCommand());
            aboutScreen.setCommandListener(this);//GEN-END:|96-getter|1|96-postInit
        // write post-init user code here
        }//GEN-BEGIN:|96-getter|2|
        return aboutScreen;
    }
    //</editor-fold>//GEN-END:|96-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: voltarAboutCommand ">//GEN-BEGIN:|98-getter|0|98-preInit
    /**
     * Returns an initiliazed instance of voltarAboutCommand component.
     * @return the initialized component instance
     */
    public Command getVoltarAboutCommand() {
        if (voltarAboutCommand == null) {//GEN-END:|98-getter|0|98-preInit
            // write pre-init user code here
            voltarAboutCommand = new Command("Voltar", Command.BACK, 0);//GEN-LINE:|98-getter|1|98-postInit
        // write post-init user code here
        }//GEN-BEGIN:|98-getter|2|
        return voltarAboutCommand;
    }
    //</editor-fold>//GEN-END:|98-getter|2|

    /**
     * Returns a display instance.
     * @return the display instance.
     */
    public Display getDisplay() {
        return Display.getDisplay(this);
    }

    /**
     * Exits MIDlet.
     */
    public void exitMIDlet() {
        switchDisplayable(null, null);
        destroyApp(true);
        notifyDestroyed();
    }

    /**
     * Called when MIDlet is started.
     * Checks whether the MIDlet have been already started and initialize/starts or resumes the MIDlet.
     */
    public void startApp() {
        if (midletPaused) {
            resumeMIDlet();
        } else {
            initialize();
            startMIDlet();
        }
        midletPaused = false;
    }

    /**
     * Called when MIDlet is paused.
     */
    public void pauseApp() {
        midletPaused = true;
    }

    /**
     * Called to signal the MIDlet to terminate.
     * @param unconditional if true, then the MIDlet has to be unconditionally terminated and all resources has to be released.
     */
    public void destroyApp(boolean unconditional) {
    }
}
